<!--
* @description 人员分数统计功能
* @fileName scoreTotal.vue
* @author huangyu
* @date 2023/02/28 22:10:50
!-->
<template>
  <div>
    <el-row>
      <el-col>
        <el-form label-width="160px">
          <el-form-item label="本次活动标题：">
            <el-input v-model="scoreForm.title" placeholder="请输入本次统计标题名称"></el-input>
          </el-form-item>
          <el-form-item label="本次统一分数：">
            <el-input v-model="scoreForm.score" placeholder="请输入分数"></el-input>
          </el-form-item>
          <el-form-item label="附近人员名单：">
            <el-button type="primary" @click="clickImageText" size="mini">上传南雨附近玩家图</el-button>
            <div v-if="personList.length>0">{{personList}}</div>
          </el-form-item>
          <div>
            <el-form-item label="筛选帮派：">
              <el-checkbox v-model="isClanPerson" @change="changeClanPerson">天上白玉金</el-checkbox>
            </el-form-item>
            <el-form-item label="本次帮派参加人员：">
              <el-row>
                <el-col :span="6" v-for="(item,index) in clanList" :key="index" style="line-height:28px;">{{item.name}}</el-col>
              </el-row>
              <!-- <el-table :data="clanList" max-height="650px" size="mini">
                <el-table-column type="index" width="50" label="序号"></el-table-column>
                <el-table-column label="名字" prop="name"></el-table-column>
                <el-table-column label="家族" prop="house"></el-table-column>
                <el-table-column label="门派" prop="sect"></el-table-column>
                <el-table-column label="积分" prop="score"></el-table-column>
              </el-table> -->
            </el-form-item>
            <el-form-item label="">
              <el-button type="primary" @click="clickForm">保存</el-button>
            </el-form-item>
          </div>
        </el-form>
      </el-col>
    </el-row>
    <el-dialog title="图片识别文字" top="50px" width="1280px" :visible.sync="dialogImageText" v-if="dialogImageText" v-dialogDrag append-to-body>
      <div style="margin-top:-40px;"></div>
      <vOrcImageText @changeValue="changeValue" :isComponents="true"></vOrcImageText>
    </el-dialog>
  </div>
</template>

<script>
import { get } from '@/common/app.js'
import vOrcImageText from "@/page/ocr/ocr_img_text.vue"
export default {
  components: {vOrcImageText},
  data() {
    return {
      scoreForm: {},
      dialogImageText: false,
      isClanPerson: false,
      personList: [],
      clanList: [],
      token: this.$store.state.token,
    };
  },
  mounted() {},
  methods: {
    clickImageText(){
      this.dialogImageText = true
    },
    changeValue(list){
      this.personList = this.personList.concat(list)
      this.dialogImageText = false
      // console.log(this.personList)
    },
    changeClanPerson(val){
      if(val&&this.personList.length>0){
        this.getClanData()
      }else{
        this.clanList = []
      }
    },
    getClanData(){
      let params = {
          type: "getClan",
          api: "api-clan-list",
          nameArr: this.personList,
          data:{
            pageIndex: 1,
            pageSize: 100,
          }
      }
      get('game',params).then(res=>{
          if(res){
            this.clanList = res.list
          }
      })
    },
    clickForm(){
      if(!this.scoreForm.title){
        this.$message.error("请输入标题！")
        return
      }
      if(!this.scoreForm.score){
        this.$message.error("请输入积分！")
        return
      }
      if(this.personList.length==0){
        this.$message.error("本次帮派无人参加，保存失败")
        return
      }

      let personIds = []
      if(this.clanList.length>0){
        this.clanList.forEach(item=>{
          personIds.push(item._id)
        })
      }
      this.scoreForm.personIds = personIds
      this.scoreForm.userId = this.token
      // console.log(this.scoreForm)
      let params = {
          type: "getClan",
          api: "api-clanscore-add",
          data: this.scoreForm,
      }
      get('game',params).then(res=>{
          if(res){
            this.$message.success("添加成功")
            this.$emit("getData")
          }
      })
    },
  },
};
</script>

<style scoped>
</style>